﻿/* Co so du lieu quan ly cua hang trang tri noi that
Date: 06/03/2013

*/
--> Tao CSDL DATABASES
USE MASTER
GO

IF EXISTS (SELECT * FROM SYSDATABASES WHERE NAME = 'DATABASES')
DROP DATABASE DATABASES
GO

CREATE DATABASE DATABASES
GO

--> - Thiet lap kieu ngay thang nam.
SET DATEFORMAT DMY
GO

--> - Dung ALXKHI, tao cac bang du lieu.
USE DATABASES
GO

-- [2] Privilege: đặc quyền
CREATE TABLE PRIVILEGE
(
	ID			int 	NOT NULL,
	Name		nvarchar(50)		NOT NULL,	-- Tên đặc quyền
	Descript	nvarchar(50)		,		-- Mô tả
	CONSTRAINT PK_tb_Privilege PRIMARY KEY(ID)
)
GO
-->14. TAI_KHOAN
CREATE TABLE ACCOUNT
(
	USERID 			VARCHAR(20)	 NOT NULL,
	PASS			VARCHAR(50) NOT NULL,
	ID				int CONSTRAINT FK_tb_User_Role FOREIGN KEY REFERENCES PRIVILEGE(ID),
	PRIMARY KEY (USERID),
	
)

GO

-- [2] Privilege: đặc quyền

Insert Into PRIVILEGE(Id, Name) Values (1, N'Administrator')
Insert Into PRIVILEGE(Id, Name) Values (2, N'Manager')
Insert Into PRIVILEGE(Id, Name) Values (3, N'Staff')
Insert Into PRIVILEGE(Id, Name) Values (4, N'User')
Insert Into PRIVILEGE(Id, Name) Values (5, N'None')

Go
---INSERT ACCOUNT

insert into ACCOUNT values('admin','admin',1)
insert into ACCOUNT values('phong','12345',2)
insert into ACCOUNT values('manager','12345',3)
insert into ACCOUNT values('staff','12345',4)
insert into ACCOUNT values('user','12345',4)
